﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PureMVC.Interfaces;
using PureMVC.Other;
using System;

namespace PureMVC.Core
{
    public partial class View
    {
        protected const string MULTITON_MSG = "View instance for this Multiton key already constructed!";
        protected static Dictionary<string, WeakLazy<IView>> instanceMap =
            new Dictionary<string, WeakLazy<IView>>();

        public static void RemoveView(string _key)
        {
            if (instanceMap.ContainsKey(_key)) instanceMap.Remove(_key);
        }

        public static IView GetInstance(string _key, Func<IView> _viewFactory)
        {
            if (!instanceMap.ContainsKey(_key))
            {
                _viewFactory();
                //instanceMap.Add(_key, new WeakLazy<IView>(_viewFactory));
            }
            return instanceMap[_key].Value;
        }
    }
}
